package com.zjj.wangluo.lianxi.tcp06;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 *
 * 写
 */
public class WriteThread implements Runnable {

    private Socket socket;

    public WriteThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (
                Scanner sc = new Scanner(System.in);
                PrintWriter pw = new PrintWriter(socket.getOutputStream());
                ){
            while (true) {
                System.out.println("请说：");
                String s = sc.nextLine();
                pw.println(s);
                pw.flush();
                if (s.equals("exit")) {
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(socket!=null){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
